<template>
  <div id="main">
    <h2>课程信息</h2>
    <div class="head">
      <el-input v-model="searchTableInfo" placeholder="请输入搜索内容" style="width:240px;float: right;margin:20px;" />
    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="studentId"
          label="学生ID"
        />

        <el-table-column
          align="center"
          prop="student.studentName"
          label="姓名"
        />

        <el-table-column
          align="center"
          prop="purchaseClazzTypeName"
          label="课程类型"
        />

        <el-table-column
          align="center"
          prop="purchasetechnicalTypeName"
          label="技术类别"
        />

        <el-table-column
          align="center"
          prop="pay.unitPrice"
          label="单价"
        />

        <el-table-column
          align="center"
          prop="pay.classHours"
          label="数量"
        />

        <el-table-column
          align="center"
          prop="pay.paySubtotal"
          label="小计"
        />

        <el-table-column
          align="center"
          prop="pay.payType"
          label="缴费类别"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.pay.payType==1">入训</span>
            <span v-if="Scope.row.pay.payType==2">续费</span>
            <span v-if="Scope.row.pay.payType==3">补费 </span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="clazz.startTime"
          label="开始时间"
        />

        <el-table-column
          align="center"
          prop="clazz.endTime"
          label="完成时间"
        />

        <el-table-column
          align="center"
          prop="purchasePeopleTeacherName"
          label="授课教师"
        />

        <el-table-column
          align="center"
          prop="purchasePrincipalTeacherName"
          label="主责教师"
        />

        <el-table-column
          align="center"
          prop="purchaseTeachingDirectorName"
          label="教学主管"
        />

        <el-table-column
          align="center"
          prop="purchaseMedicalDirectorName"
          label="医疗主管"
        />

        <el-table-column
          align="center"
          prop="clazz.classTrainingMethods"
          label="训练方式"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.clazz.classTrainingMethods==0">工作时间</span>
            <span v-if="Scope.row.clazz.classTrainingMethods==1">非工作时间</span>
            <span v-if="Scope.row.clazz.classTrainingMethods==2">持续混合</span>
            <span v-if="Scope.row.clazz.classTrainingMethods==3">不定期</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="remainingTimes"
          label="剩余课时"
        />

        <!-- <el-table-column align="center" label="操作">
          <template slot-scope="Scope">
            <el-button type="primary" icon="el-icon-edit" @click="handleOpen(Scope.row.purchaseId)">编辑</el-button>
          </template>
        </el-table-column> -->
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5, 10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <el-dialog title="课程信息详情" :close-on-click-modal="false" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <el-form ref="record" :model="record" label-position="top" :rules="rules">

        <el-form-item prop="purchaseId" label="姓名" :label-width="formLabelWidth">
          <el-input v-model="record.purchaseId" autocomplete="off" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getRecordsbyId, getAllRecords } from '@/api/purchaseCourseRecords'
export default {
// import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      tableList: [],
      listLoading: false,
      dialogFormVisible: false,
      record: {},
      newStaff: { },
      formLabelWidth: '200px',
      searchTableInfo: '',
      rules: {}
    }
  },
  // 监听属性 类似于data概念
  computed: {
    list() {
      const searchTableInfo = this.searchTableInfo
      if (searchTableInfo) {
        return this.tableList.filter(data => {
          return Object.keys(data).some(key => {
            return (
              String(data[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            )
          })
        })
      }
      return this.tableList
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    fetchData() {
      this.tableList = []
      this.listLoading = true
      getAllRecords().then(data => {
        this.tableList = data.obj
        this.listLoading = false
      })
    },
    handleOpen(id) {
      this.record = {}
      this.dialogFormVisible = true
      getRecordsbyId(id).then(resp => {
        this.record = resp.obj
        console.log(this.record)
      })
    },
    handleClose() {
      this.dialogFormVisible = false
      this.staff = {}
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>
#main {
  margin-left: 5px;
  margin-right: 5px;
}
#table-area {
  margin-left: 10px;
  margin-right: 10px;
}
</style>
